package com.tz.colawallet.ui.activity;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

import com.tz.colawallet.R;
import com.tz.colawallet.basecode.base.BaseActivity;
import com.tz.colawallet.ui.biz.ResetBiz;
import com.tz.colawallet.ui.component.DaggerResetComponent;
import com.tz.colawallet.ui.contract.ResetContract;
import com.tz.colawallet.ui.module.ResetModule;
import com.tz.colawallet.ui.presenter.ResetPresenter;

import javax.inject.Inject;

public class ResetActivity extends BaseActivity implements ResetContract.View {

    @Inject
    ResetPresenter presenter;
    @Inject
    ResetBiz biz;
    LinearLayout commonWebBack;
    EditText oldPassword;
    EditText newPassword;
    EditText newPasswordAgain;
    Button submit;

    @Override
    protected void setup() {
        super.setup();
        DaggerResetComponent.builder().resetModule(new ResetModule(this)).build().inject(this);
        presenter.setBiz(biz);
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_reset;
    }

    @Override
    protected void init() {
        commonWebBack = findViewById(R.id.common_web_back);
        oldPassword = findViewById(R.id.old_password);
        newPassword = findViewById(R.id.new_password);
        newPasswordAgain = findViewById(R.id.new_password_again);
        submit = findViewById(R.id.submit);

        submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (oldPassword.getText().toString().isEmpty()) {
                    showToast("请输入原密码");
                    return;
                }
                if (newPassword.getText().toString().isEmpty() || newPassword.getText().toString().length() < 6) {
                    showToast("请输入新密码(最少6位)");
                    return;
                }
                if (newPasswordAgain.getText().toString().isEmpty() || newPasswordAgain.getText().toString().length() < 6) {
                    showToast("请输入新密码(最少6位)");
                    return;
                }
                if (!newPasswordAgain.getText().toString().equals(newPassword.getText().toString())) {
                    showToast("输入的两次新密码不一致");
                    return;
                }
                presenter.reset(oldPassword.getText().toString(), newPassword.getText().toString());
            }
        });

        commonWebBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

    }

    @Override
    protected void initTitle() {
    }

    @Override
    public Context curContext() {
        return this;
    }

    @Override
    public void loginSuccess(Object o) {
        showToast("重置密码成功");
        finish();
    }

}
